package com.geek.service.impl;

import com.geek.mapper.MarketOrderGoodsMapper;
import com.geek.model.MarketCart;
import com.geek.model.MarketOrderGoods;
import com.geek.service.OrderGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author wbw
 * @data 2024/06/17 22:08
 **/
@Service
public class OrderGoodsServiceImpl implements OrderGoodsService {
    @Autowired
    MarketOrderGoodsMapper orderGoodsMapper;
    @Override
    public void insertByCartSubmit(int orderId, List<MarketCart> cartList) {
        Date current = new Date();
        for (MarketCart cart : cartList) {
            MarketOrderGoods orderGoods = MarketOrderGoods.builder()
                    .orderId(orderId)
                    .goodsId(cart.getGoodsId())
                    .goodsName(cart.getGoodsName())
                    .goodsSn(cart.getGoodsSn())
                    .productId(cart.getProductId())
                    .number(cart.getNumber())
                    .price(cart.getPrice())
                    .specifications(cart.getSpecifications())
                    .picUrl(cart.getPicUrl())
                    .comment(0)
                    .addTime(current)
                    .updateTime(current)
                    .deleted(false).build();
            orderGoodsMapper.insert(orderGoods);
        }
    }

    @Override
    public void insertByFastSubmit(int orderId, MarketCart marketCart) {
        Date current = new Date();
        MarketOrderGoods orderGoods = MarketOrderGoods.builder()
                .orderId(orderId)
                .goodsId(marketCart.getGoodsId())
                .goodsName(marketCart.getGoodsName())
                .goodsSn(marketCart.getGoodsSn())
                .productId(marketCart.getProductId())
                .number(marketCart.getNumber())
                .price(marketCart.getPrice())
                .specifications(marketCart.getSpecifications())
                .picUrl(marketCart.getPicUrl())
                .comment(0)
                .addTime(current)
                .updateTime(current)
                .deleted(false).build();
        orderGoodsMapper.insert(orderGoods);
    }
}
